<?php

/*
	Data Access Object for club module
*/

require_once(FWS_DIR_MODEL.'clubmodel.class.php');

class ClubModelDao {

	function findAllClub() {
       	$resultat = mysql_query("SELECT ID_CLUB, LIB_CLUB, COD_CLUB_FFT, COLOUR FROM TBL_CLUB ORDER BY LIB_CLUB") or trigger_error(mysql_error(), E_USER_ERROR);
		$result = array();
       	while($row = mysql_fetch_array($resultat)) {
			$result[] = new ClubModel($row);
   		}
		return $result;
	}

	function findRefClub() {
       	$resultat = mysql_query("SELECT ID_CLUB, LIB_CLUB FROM TBL_CLUB ORDER BY LIB_CLUB") or trigger_error(mysql_error(), E_USER_ERROR);
		$result = array();
       	while($row = mysql_fetch_array($resultat)) {
			$result[$row[0]] = $row[1]; 			
   		}
		return $result;
	}

	
	function queryClubById($id_club) {
		$query = "SELECT ID_CLUB, LIB_CLUB, COD_CLUB_FFT, COLOUR "
			."FROM TBL_CLUB "
			."WHERE ID_CLUB=$id_club";
		$result = mysql_query ($query) or trigger_error(mysql_error(), E_USER_ERROR);
		$row = mysql_fetch_assoc($result);
		$club = new ClubModel($row); 
		return $club;
	}

		
	function updateClub($club) {
		$clubs = array();
		$query  = "UPDATE TBL_CLUB SET LIB_CLUB='".$club->getLib_Club();
		$query .= "', COD_CLUB_FFT='".$club->getCod_club_fft();
		$query .= "', COLOUR='".$player->getCouleur();
		$query .= "' WHERE ID_CLUB =".$club->getId_club();
		$result = mysql_query ($query) or trigger_error(mysql_error(), E_USER_ERROR);
	}
	
	function insertClub($club) {
		$clubs = array();
		$query  = "INSERT INTO TBL_CLUB(LIB_CLUB, COD_CLUB_FFT,";
		$query .= "COLOUR)";
		$query .= "VALUES('".$club->getLib_Club()."', '";
		$query .= $club->getCod_club_fft()."', '";
		$query .= $club->getCouleur()."')";
		$result = mysql_query ($query) or trigger_error(mysql_error(), E_USER_ERROR);
	}
}
?>